package org.wsocket.utils;

public class StringUtil {
	/**
	 * fromStringToIntArray 
	 * 
	 * @param s
	 * @param regex
	 * @return
	 */
	public static int[] fromStringToIntArray(String s, String regex){
		if (isEmpty(s)){
			return null;
		}
		
		String[] str = s.split(regex);
		int num = str.length;
		int[] intArray = new int[num];
		for (int i = 0; i < num; i++) {
			intArray[i] = Integer.parseInt(str[i]);
		}
		return intArray;
	}
	
    /**
     * Determine whether a (trimmed) string is empty
     * @param foo The text to check.
     * @return Whether empty.
     */
    public static final boolean isEmpty(String foo) {
        return (foo == null || foo.trim().length() == 0);
    }
	
	public static void main(String[] arg){
		String s = "1,25,333,454";
		int[] a = fromStringToIntArray(s,",");
		for (int x:a){
			System.out.print(x);
			System.out.print("--");
		}
	} 
}
